package com.fotile.weixin.work.aes;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.UnsupportedEncodingException;


public class OAuth2Util {
	private static final String QY_OAuth2URL="https://open.weixin.qq.com/connect/oauth2/authorize";
	private static Log log = LogFactory.getLog(OAuth2Util.class);
	/** 
     * 构造带员工身份信息的URL 
     * @param corpid    企业id 
     * @param redirect_uri   授权后重定向的回调链接地址，请使用urlencode对链接进行处理 
     * @param state  重定向后会带上state参数，企业可以填写a-zA-Z0-9的参数值 
     * @return 
     */  
    public static String oAuth2Url(String corpid, String redirect_uri) {  
        try {  
            redirect_uri = java.net.URLEncoder.encode(redirect_uri, "utf-8");  
        } catch (UnsupportedEncodingException e) {  
            e.printStackTrace();  
        }  
        String oauth2Url =QY_OAuth2URL+"?appid=" + corpid + "&redirect_uri=" + redirect_uri  
                + "&response_type=code&scope=snsapi_base&state=sunlight#wechat_redirect";  
        log.error(System.currentTimeMillis()+"_构造完认证地址:" + oauth2Url);
        return oauth2Url;  
    }  
}
